#! /bin/bash
set -euo pipefail
base_module=(kernel gcc glibc zlib systemd libxml2 e2fsprogs curl grep iputils)
res=0

echo -e "\033[31m请输入被测OS对应的openEuler版本镜像文件绝对路径：\033[0m"
read -p "> " openeuler_ISO
#创建挂载路径，并挂载openeuler镜像
if [ ! -d "/oemount/iso" ];then
	mkdir -p /oemount/iso
fi
mount ${openeuler_ISO}  /oemount/iso
for i in ${base_module[@]};do
	echo "开始测试$i软件包"
	test_os_package_ver=$(rpm -qa | grep "^$i-[0-9]" | awk -F"-" {'print $1,$2'})
	oe_package_ver=$(ls /oemount/iso/Packages | grep "^$i-[0-9]" | awk -F"-" {'print $1,$2'})
	echo "被测试系统软件包名及版本信息：                 $test_os_package_ver"
	echo "被测试系统对应openeuler版本软件包名及版本信息：$oe_package_ver"
	[ "$test_os_package_ver" == "$oe_package_ver" ] && echo -e "\033[32m被测试系统$i 软件包与openEuler版本对应软件包版本号一致\033[0m" || res=1
	echo -e "\n"
done
# 判断用例是否执行成功
[ "$res" = "0" ] && echo -e "\033[32m-----------------test PASSED----------------\033[0m" || echo -e "\033[31m-----------------test FAILED----------------\033[0m"

#后处理
umount /oemount/iso
rm -rf /oemount/iso
